package com.yanqu.road.entity.activity.diggold.config;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.config.system.NormalWeightItem;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class DigGoldConfig {

    private int scoreItemId;

    private int digItemId;


    private int scorePerItem;

    private int drillItemId;

    private int bombItemId;

    private int boxNumPerPalace;

    private int digGoldGuarantees;


    //挖金活动古董配置
    Map<Integer,DigGoldAntiqueConfig> antiqueConfigMap;
    Map<Integer,Map<Integer,Integer>> antiqueWeightMap;

    //挖金活动方块配置
    Map<Integer,DigGoldBlockConfig> blockConfigMap;

    //挖金活动地图配置
    Map<Integer,DigGoldMapConfig> mapConfigMap;
    //挖金活动地图权重配置
    Map<Integer,List<NormalWeightItem>> mapWeightMap;

    //挖金活动土层配置
    Map<Integer,DigGoldStratumConfig> stratumConfigMap;

    //随机铲子数量配置
    List<NormalWeightItem> randomShovelNumList;

    public DigGoldConfig(Map<Integer, DigGoldAntiqueConfig> antiqueConfigMap,
                         Map<Integer, DigGoldBlockConfig> blockConfigMap,
                         Map<Integer, DigGoldMapConfig> mapConfigMap,
                         Map<Integer, DigGoldStratumConfig> stratumConfigMap,
                         Map<String, ActivityConfig> activityConfigMap
                         ) {
        this.antiqueConfigMap = antiqueConfigMap;
        this.blockConfigMap = blockConfigMap;
        this.mapConfigMap = mapConfigMap;
        this.stratumConfigMap = stratumConfigMap;
        this.scoreItemId = activityConfigMap.get("EXCHANGE_SCORE_ITEM_ID").getIntValue();
        this.digItemId = activityConfigMap.get("DIG_GOLD_ENERGY_ITEM_ID").getIntValue();
        this.scorePerItem = activityConfigMap.get("DIG_GOLD_ACHIEVE_SCORE_ITEM_NUMBER").getIntValue();
        this.drillItemId = activityConfigMap.get("DIG_GOLD_DRILL_ID").getIntValue();
        this.bombItemId = activityConfigMap.get("DIG_GOLD_DYNAMITE_ID").getIntValue();
        this.boxNumPerPalace = activityConfigMap.get("DIG_GOLD_TREASURE_NUMBER").getIntValue();
        this.digGoldGuarantees = activityConfigMap.get("DIG_GOLD_GUARANTEES").getIntValue();

        this.mapWeightMap = new ConcurrentHashMap<>();
        for (DigGoldMapConfig mapConfig : this.mapConfigMap.values()) {
            NormalWeightItem weightItem = new NormalWeightItem();
            weightItem.setWeight(mapConfig.getWeight());
            weightItem.setValue(BigInteger.valueOf(mapConfig.getId()));
            this.mapWeightMap.putIfAbsent(mapConfig.getType(), new ArrayList<>());
            List<NormalWeightItem> normalWeightItems = this.mapWeightMap.get(mapConfig.getType());
            normalWeightItems.add(weightItem);
        }

        for (DigGoldMapConfig mapConfig:this.mapConfigMap.values()){
            //解析地图的炸药和地钻权重
            mapConfig.setDrillWeightList(NormalWeightItem.parseWeightItemList(mapConfig.getDrillWeight()));
            mapConfig.setDynamiteWeightList(NormalWeightItem.parseWeightItemList(mapConfig.getDynamiteWeight()));
            mapConfig.setShovelWeightList(NormalWeightItem.parseWeightItemList(mapConfig.getShovelWeight()));
            mapConfig.setAntiqueNumList(new ArrayList<>());
            mapConfig.setAntiqueWeightList(new ArrayList<>());

            //解析古董权重  0;1;2;4,600|1;1;2;4,300|1;2;3;4,100
            List<String> strings = StringUtils.stringToStringList(mapConfig.getAntiqueWeight(), "\\|");
            for (String str:strings){//0;1;2;4,600
                List<String> numWeight = StringUtils.stringToStringList(str, ",");
                String num = numWeight.get(0);      //0;1;2;4
                String weight = numWeight.get(1);   //600
                mapConfig.getAntiqueNumList().add(num);
                mapConfig.getAntiqueWeightList().add(Integer.parseInt(weight));
            }
        }

        antiqueWeightMap = new ConcurrentHashMap<>();
        for (DigGoldAntiqueConfig antiqueConfig:this.antiqueConfigMap.values()){
            antiqueWeightMap.putIfAbsent(antiqueConfig.getType(),new ConcurrentHashMap<>());
            Map<Integer,Integer> weightMap = antiqueWeightMap.get(antiqueConfig.getType());
            weightMap.put(antiqueConfig.getAntiqueId(),antiqueConfig.getWeight());
        }

        String digGoldShovelParam = activityConfigMap.get("DIG_GOLD_SHOVEL_PARAM").getValue();
        randomShovelNumList = NormalWeightItem.parseWeightItemList(digGoldShovelParam);

    }

    public Map<Integer, DigGoldAntiqueConfig> getAntiqueConfigMap() {
        return antiqueConfigMap;
    }

    public void setAntiqueConfigMap(Map<Integer, DigGoldAntiqueConfig> antiqueConfigMap) {
        this.antiqueConfigMap = antiqueConfigMap;
    }

    public Map<Integer, DigGoldBlockConfig> getBlockConfigMap() {
        return blockConfigMap;
    }

    public void setBlockConfigMap(Map<Integer, DigGoldBlockConfig> blockConfigMap) {
        this.blockConfigMap = blockConfigMap;
    }

    public Map<Integer, DigGoldMapConfig> getMapConfigMap() {
        return mapConfigMap;
    }

    public void setMapConfigMap(Map<Integer, DigGoldMapConfig> mapConfigMap) {
        this.mapConfigMap = mapConfigMap;
    }

    public Map<Integer, DigGoldStratumConfig> getStratumConfigMap() {
        return stratumConfigMap;
    }

    public void setStratumConfigMap(Map<Integer, DigGoldStratumConfig> stratumConfigMap) {
        this.stratumConfigMap = stratumConfigMap;
    }

    public int getScoreItemId() {
        return scoreItemId;
    }

    public int getDigItemId() {
        return digItemId;
    }

    public int getScorePerItem() {
        return scorePerItem;
    }

    public int getDrillItemId() {
        return drillItemId;
    }

    public int getBombItemId() {
        return bombItemId;
    }

    public Map<Integer, List<NormalWeightItem>> getMapWeightMap() {
        return mapWeightMap;
    }

    public Map<Integer, Map<Integer, Integer>> getAntiqueWeightMap() {
        return antiqueWeightMap;
    }


    public int getBoxNumPerPalace() {
        return boxNumPerPalace;
    }

    public int getDigGoldGuarantees() {
        return digGoldGuarantees;
    }

    public List<NormalWeightItem> getRandomShovelNumList() {
        return randomShovelNumList;
    }
}
